Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Is there an easy way to use nested object > array key in string form?

What I have is some kind of object, structure is unknown to me beforehand, and I also receive the key (in the string form) for some value that I need, that is contained inside that object. The problem arises when the value I need is nested inside an array.


let someObject = {
  nonProblematicValue: "all good",
  arrayOfValues: ["can't touch this"]
}
let keyThatWorks = "nonProblematicValue";
let keyThatDoesNotWork = "arrayOfValues[0]"

I've tried

someObject[keyThatDoesNotWork] //undefined
someObject.[keyThatDoesNotWork]  //undefined

I know that it could be done using eval, but that is not an option because of the server setup.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use Lodash#get:

let someObject = {
  nonProblematicValue: "all good",
  arrayOfValues: ["can't touch this"]
}

let keyThatDoesNotWork = "arrayOfValues[0]"
console.log(_.get(someObject, keyThatDoesNotWork))
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!